<template>
  <a-card class="j-inner-table-wrapper" :bordered="false">

    <!-- 查询区域 begin -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24" v-if="accCode == '' ">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="户号">
          <!-- <j-dict-select-tag v-model="queryParam.cusId" placeholder="请选择户号" dictCode="mws_t_arc_customers,code,id"/> -->
              <a-input placeholder="请输入户号" class="query-group-cust" v-model="queryParam.cusId" style="width:100%"></a-input> 
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="户名">
             <a-input v-model="queryParam.cusName" placeholder="请输入户名"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="抄表月份">
               <a-input v-model="queryParam.readMonth" placeholder="请输入抄表月份"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="收费员">
              <a-input v-model="queryParam.createBy" placeholder="请输入收费员登录名"/>
              </a-form-item>
            </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="收费方式">
          <j-dict-select-tag v-model="queryParam.feeChargeType" placeholder="请选择收费方式" dictCode="fee_charge_type"/>
            </a-form-item>
          </a-col> -->
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="冲账状态">
          <j-dict-select-tag v-model="queryParam.feeStruckStatus" placeholder="请选择冲账状态" dictCode="fee_struck_status"/>
            </a-form-item>
          </a-col> -->
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons table-operator">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" @click="searchReset">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                <span>{{ toggleSearchStatus ? '收起' : '展开' }}</span>
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域 end -->

    <!-- 操作按钮区域 begin -->
    <div class="table-operator" v-if="accCode == '' ">
      <a-button type="primary" icon="plus" @click="handleAdd" v-if="username == 'admin'">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('收费记录')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            <span>删除</span>
          </a-menu-item>
        </a-menu>
        <a-button>
          <span>批量操作</span>
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
       <span>已选择</span>
          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
    </div>
    <!-- 操作按钮区域 end -->

    <!-- table区域 begin -->
    <div>

      <!-- <a-alert type="info" showIcon style="margin-bottom: 16px;">
        <template slot="message">
          <span>已选择</span>
          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </template>
      </a-alert> -->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :expandedRowKeys="expandedRowKeys"
        :rowSelection="{selectedRowKeys, onChange: onSelectChange}"
        @expand="handleExpand"
        @change="handleTableChange"
      >

        <!-- 内嵌table区域 begin -->
        <template slot="expandedRowRender" slot-scope="record">
          <a-tabs tabPosition="top">
            <a-tab-pane tab="收费明细" key="chgSubFees" forceRender>
              <chg-sub-fees-sub-table :record="record"/>
            </a-tab-pane>
          </a-tabs>
        </template>
        <!-- 内嵌table区域 end -->

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="ellipsisText" slot-scope="text">
          <j-ellipsis :value="text" :length="textMaxLength"></j-ellipsis>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <div style="font-size: 12px;font-style: italic;">
            <span v-if="!text">无图片</span>
            <img v-else :src="getImgView(text)" alt="" style="max-width:80px;height:25px;"/>
          </div>
        </template>


        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            ghost
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)"
          >
            <span>下载</span>
          </a-button>
        </template>

        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">
              <span>更多 <a-icon type="down"/></span>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>

        </template>

      </a-table>
    </div>
    <!-- table区域 end -->

    <!-- 表单区域 -->
    <chg-fees-modal ref="modalForm" @ok="modalFormOk"/>

  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ChgFeesModal from './modules/ChgFeesModal'
  import ChgSubFeesSubTable from './subTables/ChgSubFeesSubTable'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'

  export default {
    name: 'ChgFeesList',
    mixins: [JeecgListMixin],
    components: {
      ChgFeesModal,
      ChgSubFeesSubTable,
      JDictSelectTag,
    },
    props: {
      accCode:{
        type: String,       
        default: ''
      }
    },
    data() {
      return {
        description: '收费记录列表管理页面',
        disableMixinCreated:true,
        textMaxLength:5,
        username:'',
        // 表头
        columns: [
          {
            title: '#',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: (t, r, index) => parseInt(index) + 1
          },
          {
            title: '户号',
            align: 'center',
            dataIndex: 'cusId'
          },
          {
            title: '户名',
            align: 'center',
            dataIndex: 'cusName',
            scopedSlots: {customRender: "ellipsisText"}
          },
          {
            title: '抄表月份',
            align: 'center',
            dataIndex: 'readMonth',
          },
          {
            title: '起度',
            align: 'center',
            dataIndex: 'beginScale',
          },
          {
            title: '止度',
            align: 'center',
            dataIndex: 'endScale',
          },
          {
            title: '水量',
            align: 'center',
            dataIndex: 'amount',
          },
          {
            title: '水费',
            align: 'center',
            dataIndex: 'totalMoney',
          },
          {
            title:'污水费',
            align:"center",
            dataIndex: 'wuMoney'
          },
          {
            title:'垃圾费',
            align:"center",
            dataIndex: 'ljMoney'
          },
          {
            title: '杂项费',
            align: 'center',
            dataIndex: 'alienMoney',
          },
          // {
          //   title: '收费方式',
          //   align: 'center',
          //   dataIndex: 'feeChargeType_dictText'
          // },
          // {
          //   title: '增值税金额',
          //   align: 'center',
          //   dataIndex: 'vatMoney',
          // }, 
          {
            title: '违约金',
            align: 'center',
            dataIndex: 'penalty',
          },
          {
            title: '费用金额',
            align: 'center',
            dataIndex: 'money',
          },
          {
            title: '前次余额',
            align: 'center',
            dataIndex: 'preBalance',
          },
          // {
          //   title: '预存缴费金额',
          //   align: 'center',
          //   dataIndex: 'storedPaymentMoney',
          // },
         
          // {
          //   title: '实收金额',
          //   align: 'center',
          //   dataIndex: 'recivedMoney',
          // },
          
          {
            title: '本次余额',
            align: 'center',
            dataIndex: 'postBalance',
          },
          
          // {
          //   title: '抄表本',
          //   align: 'center',
          //   dataIndex: 'bookId_dictText'
          // },
          // {
          //   title: '冲账状态',
          //   align: 'center',
          //   dataIndex: 'feeStruckStatus'
          // },
          {
            title: '财务月份',
            align: 'center',
            dataIndex: 'financialMonth',
          },
          {
            title: '收费员',
            align: 'center',
            dataIndex: 'createBy'
          },
          {
            title: '时间',
            align: 'center',
            dataIndex: 'financialDate',
          },
          // {
          //   title: '状态',
          //   align: 'center',
          //   dataIndex: 'status'
          // },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align: 'center',
          //   width:147,
          //   scopedSlots: { customRender: 'action' },
          // },
        ],
        // 字典选项
        dictOptions: {},
        // 展开的行test
        expandedRowKeys: [],
        url: {
          list: '/chg/chgFees/list',
          delete: '/chg/chgFees/delete',
          deleteBatch: '/chg/chgFees/deleteBatch',
          exportXlsUrl: '/chg/chgFees/exportXls',
          importExcelUrl: '/chg/chgFees/importExcel',
        },
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
      this.username = this.userInfo.username;
      this.queryParam.cusId=this.accCode;
      if(this.accCode){
        this.loadData();
      }
    },
    computed: {
      importExcelUrl() {
        return window._CONFIG['domianURL'] + this.url.importExcelUrl
      },
      userInfo() {
        return this.$store.getters.userInfo
      }  
    },
    methods: {
      initDictConfig() {
      },

      handleExpand(expanded, record) {
        this.expandedRowKeys = []
        if (expanded === true) {
          this.expandedRowKeys.push(record.id)
        }
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'cusId',text:'户号',dictCode:'mws_t_arc_customers,code,id'})
        fieldList.push({type:'string',value:'cusName',text:'户名',dictCode:''})
        fieldList.push({type:'string',value:'readMonth',text:'抄表月份',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'beginScale',text:'起度',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'endScale',text:'止度',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'amount',text:'水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'totalMoney',text:'合计金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'lajifee',text:'垃圾费',dictCode:''})
        fieldList.push({type:'string',value:'feeChargeType',text:'收费方式',dictCode:'fee_charge_type'})
        fieldList.push({type:'BigDecimal',value:'preBalance',text:'前次余额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'storedPaymentMoney',text:'预存缴费金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'penalty',text:'违约金',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'money',text:'费用金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'recivedMoney',text:'实收金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'postBalance',text:'本次余额',dictCode:''})
        fieldList.push({type:'sel_user',value:'readerId',text:'抄表员'})
        fieldList.push({type:'string',value:'bookId',text:'抄表本',dictCode:''})
        fieldList.push({type:'int',value:'feeStruckStatus',text:'冲账状态',dictCode:'fee_struck_status'})
        fieldList.push({type:'string',value:'financialMonth',text:'财务月份',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'status',text:'状态',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style lang="less" scoped>
  @import '~@assets/less/common.less';
</style>